﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ListenMusic.Song_ServiceReference;
using ListenMusic.Category_ServiceReferences;
using ListenMusic.Album_ServiceReference;
using ListenMusic.Models.Public;
using ListenMusic.Models.ViewModel;
using System.ServiceModel;
namespace ListenMusic.Controllers.Public
{
    public class HomeController : ApplicationController
    {
        private AlbumRepository ap;
        private CategoryRepository cp;
        private SingerRepository sp;
        private SongRepository sop;
        public HomeController()
        {
            ap = new AlbumRepository();
            cp = new CategoryRepository();
            sp = new SingerRepository();
            sop = new SongRepository();
        }
        public ActionResult Index()
        {          
            try
            {
                var lst_album = ap.getAllAlbum();
                var lst_category = cp.getAllCategory();
                var lst_singerVN = sp.getSingerByCountry(1);
                var lst_singerAM = sp.getSingerByCountry(2);
                var lst_albumVN = ap.getAllAlbumByCountry(1);
                var lst_albumAM = ap.getAllAlbumByCountry(2);
                var lst_topSong = sop.getTopSong(10,1);
                var lst_topAlbum = ap.gettopAlbum(10);
                var lst_newAlbum = ap.getnewAlbum(8);
                var lst_topVideo = sop.getTopSong(10, 2);
                var lst_newSong = sop.getnewSong(20);
                var _song = sop.getSongById(1);             
                var viewModel = new ListenMusic.Models.ViewModel.IndexViewModel
                {
                    album = lst_album,
                    category = lst_category,
                    singerVN = lst_singerVN,
                    singerAM = lst_singerAM,
                    albumVN = lst_albumVN,
                    albumAM = lst_albumAM,
                    newAlbum = lst_newAlbum,
                    song = _song,
                    topAlbum = lst_topAlbum,
                    topSong = lst_topSong,
                    newSong = lst_newSong,
                    topVideo = lst_topVideo,
                };
                return View(viewModel);
            }
            catch (FaultException ex)
            {
                throw ex;
                //ViewPage.Message = ex.Reason;
            }
             
        }  
    }
}


